package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author lwm
 * @since 2022-02-10
 */
@Api(tags = "借款人")
@RestController
@RequestMapping("/api/core/borrower")
@Slf4j
public class BorrowerController {
    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("额度申请,提交借款人信息")
    @PostMapping("/auth/save")
    public R save(@RequestBody BorrowerVO borrowerVO, @RequestHeader String token){
        //校验token
        Long userId = JwtUtils.getUserId(token);
        //提交借款人信息
        borrowerService.saveBorrower(borrowerVO,userId);
        return R.ok().message("信息提交成功");
    }

    @ApiOperation("获取借款人的审核状态")
    @GetMapping("/auth/getBorrowerStatus")
    public R getBorrowerStatus(@RequestHeader String token){
        Long userId = JwtUtils.getUserId(token);
        //获取最近一次借款的审核状态
        Integer status = borrowerService.getBorrowerStatus(userId);
        return R.ok().data("borrowerStatus", status);
    }
}

